/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Node;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.NodeList;

/**
 *
 * @author Hoang
 */
public class XPathUtils {

    public static Node selectSingleNode(Node node, String xPath) throws XPathExpressionException {
            XPathFactory xpf = XPathFactory.newInstance();
            XPath xpath = xpf.newXPath();
            Node result = (Node) xpath.evaluate(xPath,
                    node, XPathConstants.NODE);
            return result;
    }

    public static NodeList selectNodes(Node node, String xPath) throws XPathExpressionException {

            XPathFactory xpf = XPathFactory.newInstance();
            XPath xpath = xpf.newXPath();
            NodeList result = (NodeList) xpath.evaluate(xPath,
                    node, XPathConstants.NODESET);
            return result;

    }
}
